/**
 * 
 */
package vn.smartware.co.framework.action;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import vn.smartware.co.framework.exception.FatalException;
import vn.smartware.co.framework.exception.ServerException;
import vn.smartware.co.framework.exception.SessionTimeOutException;
import vn.smartware.co.framework.form.ActionForm;
import vn.smartware.co.framework.plugin.FileResource;


/**
 * ClientAction Class
 * @author thuctt
 * created 2009/09/01
 */
public abstract class ClientAction {
    
    private static Log log = LogFactory.getLog(ClientAction.class);
    
    /**
     * fileResource
     */
    protected FileResource fileResource;
    
    /**
     * processActionPerform
     * @param form
     * @return ActionForm
     * @throws FatalException
     * @throws ServerException 
     * @throws SessionTimeOutException 
     */
	abstract public ActionForm processActionPerform(ActionForm form)
			throws FatalException, ServerException, SessionTimeOutException;
	
	/**
	 * processValidator
	 * @param form
	 * @throws FatalException 
	 * @throws ServerException 
	 * @throws SessionTimeOutException 
	 * @throws ClientException
	 */
//	abstract public void processValidator(ActionForm form)
//			throws FatalException, ServerException, SessionTimeOutException;
	
	/**
	 * execute a method in client request
	 * execute: 
	 * @param form
	 * @return ActionForm
	 * @throws FatalException 
	 * @throws ServerException 
	 * @throws SessionTimeOutException 
	 */
	public ActionForm execute(ActionForm form) throws FatalException,
			ServerException, SessionTimeOutException {
		
	    long startTime = System.currentTimeMillis();
	    
	    fileResource = FileResource.getInstance();
	    
//		processValidator(form);
		
		form = processActionPerform(form);
		
		long endTime = System.currentTimeMillis();
		
		log.debug("Processing time : " + (endTime - startTime) / 1000.0 + " Second.");
		
		return form;
	}
}
